/*
 * Copyright 2003-2007 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

package com.colony.networkvm;

import com.argot.TypeLibrary;
import com.colony.ColonyEnvironment;
import com.colony.IColonyClient;
import com.colony.IContainer;
import com.colony.networkvm.machine.NvmInstance;
import com.colony.networkvm.machine.NvmState;
import com.colony.remote.RemoteException;

public class NvmEnvironment
{
	private TypeLibrary _library;
	private ColonyEnvironment _environment;
	private NvmDelegateFactory _delegateFactory;
		
	public NvmEnvironment( ColonyEnvironment environment, NvmDelegateFactory delegateFactory, TypeLibrary library ) 
	{
		_environment = environment;
		_library = library;
		_delegateFactory = delegateFactory;
	}
	
	// proxies to access object in local container.
	public void setBackDelegate( Class type, NvmProxyDelegate delegate )
	{
		_delegateFactory.setBackDelegate( type, delegate );
	}
	
	public NvmProxyDelegate getBackDelegate( Class type )
	{
		return (NvmProxyDelegate) _delegateFactory.getBackDelegate( type );
	}
	
	public IColonyClient getClient( String hostName )
	{
		return _environment.getClient( hostName );
	}

	// create a new NetworkVM
	public NvmInstance getNvmInstance( )
	{
		return new NvmInstance( this, _library );
	}

	public NvmInstance getNvmInstance(NvmState state)
	{
        
		return new NvmInstance( this, _library, state );
	}
	
	public void executeInstance( NvmInstance instance ) 
	throws RemoteException
	{
		instance.execute( instance );
	}
	
	public IContainer getHostContainer()
	{
		return _environment.getHostContainer();
	}

	// System type library.
    public TypeLibrary getTypeLibrary()
    {
        return _library;
    }	
}
